package cn.zzf.service.impl;

import cn.zzf.bean.User;
import cn.zzf.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author GaoFeng2017
 * @date 2018-06-28 15:54:57
 **/

@Service
public class UserServiceImpl implements cn.zzf.service.UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional(rollbackFor = RuntimeException.class,propagation = Propagation.REQUIRED)
    public void add(User user) {
        userMapper.insertUser(user);
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class,propagation = Propagation.REQUIRES_NEW)
    public void update(User user) {
        userMapper.updateUser(user);
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class,propagation = Propagation.REQUIRES_NEW)
    public void updateNewException(User user) {
        userMapper.updateUser(user);
        throw new RuntimeException();
    }


    @Override
    @Transactional(rollbackFor = RuntimeException.class,propagation = Propagation.NESTED)
    public void insertNestedException(User user) {
        userMapper.insertUser(user);
        throw new RuntimeException();
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class,propagation = Propagation.NESTED)
    public void insertNested(User user) {
        userMapper.insertUser(user);
//        throw new RuntimeException();
    }
}
